//
//  PresidentTableViewController.m
//  11402
//
//  Created by Clement_Gu on 16/3/10.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "PresidentTableViewController.h"

@interface PresidentTableViewController ()
@property(nonatomic,strong)NSDictionary *president;
@end

@implementation PresidentTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString *path=[[NSBundle mainBundle]pathForResource:@"PresidentList" ofType:@"plist"];
    self.president=[NSDictionary dictionaryWithContentsOfFile:path];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"xiaobai"];
    
    self.title=@"历任总统";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSArray *arr=self.president[@"presidents"];

    return arr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"xiaobai" forIndexPath:indexPath];
    
    NSArray *arr=self.president[@"presidents"];
    NSDictionary *dict=arr[indexPath.row];

    cell.textLabel.text=dict[@"name"];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *arr=self.president[@"presidents"];
    NSDictionary *dict=arr[indexPath.row];
    NSString *str=dict[@"url"];
    
    NSURL *url=[NSURL URLWithString:str];
 
    self.detailVC.detailUrl=url;
    
}
@end
